package org.lex.dbq.model.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.IdentityHashMap;
import java.util.Map;

import org.lex.dbq.model.bo.SQLMetaData;

public class MetaDataService {
	private static final MetaDataService INSTANCE = new MetaDataService();

	public static MetaDataService getInstance() {
		return INSTANCE;
	}

	public synchronized SQLMetaData get(Connection conn) throws SQLException {
		SQLMetaData md = map.get(conn);
		if (null == md) {
			md = SQLMetaData.newInstance(conn);
			map.put(conn, md);
		}
		return md;
	}

	private Map<Connection, SQLMetaData> map = null;

	private MetaDataService() {
		map = new IdentityHashMap<Connection, SQLMetaData>();
	}
}
